(function() {
    angular.module('app').factory('wordsControllerComponentService', wordsControllerComponentService);

    wordsControllerComponentService.$inject = ['util', '$q'];

    function wordsControllerComponentService(util, $q) {

        return {

            getLineData: _getLineData,
            getTopProduct: _getTopProduct,
            getTopShop: _getTopShop
        }


        function _getLineData(json) {

            var defer = $q.defer();

            util.$get({
                url: '/marketconditions/word/getLeafWordIndex.htm',
                data: json
            }).then(function(resp) {

                defer.resolve(resp.value);


            }, function(err) {

                defer.reject(err);

            });

            return defer.promise;
        }

        function _getTopProduct(json) {

            var defer = $q.defer();

            util.$get({
                url: '/marketconditions/word/getLeafWordTopProduct.htm',
                data: json
            }).then(function(resp) {

                defer.resolve(resp.value.product);


            }, function(err) {

                defer.reject(err);

            });

            return defer.promise;
        }

        function _getTopShop(json) {

            var defer = $q.defer();

            util.$get({
                url: '/marketconditions/word/getLeafWordTopShop.htm',
                data: json
            }).then(function(resp) {

                defer.resolve(resp.value.shop);


            }, function(err) {

                defer.reject(err);

            });

            return defer.promise;
        }
    }


})();
